# cmake requirement
cmake_minimum_required(VERSION 3.8)

# Disable in-source builds to prevent source tree corruption.
if(" ${CMAKE_SOURCE_DIR}" STREQUAL " ${CMAKE_BINARY_DIR}")
  message(FATAL_ERROR "
FATAL: In-source builds are not allowed.
       You should create a separate directory for build files.
")
endif()

# project name
project("libswmmoutputapi")

# --------------------------------------------------------------
# 判断平台
if(CMAKE_HOST_WIN32)
     message(STATUS "当前平台为Windows")
     if(MINGW)
        message(STATUS "编译器为MinGW")
     endif(MINGW)
elseif(CMAKE_HOST_APPLE)
    message(STATUS "当前平台为Apple OSX")
elseif(CMAKE_HOST_UNIX)
     message(STATUS "当前平台为Linux")
else()
    message(STATUS "当前平台为 ${CMAKE_SYSTEM_NAME}")
endif()

# --------------------------------------------------------------
# set output directory
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin)

# --------------------------------------------------------------
# CXX standard
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 编译选项
option(BUILD_WITH_TEST "build test main" ON)
# --------------------------------------------------------------
# 编译参数
set(CMAKE_C_FLAGS_DEBUG "$ENV{CFLAGS} -O0 -Wall -g -ggdb")
set(CMAKE_C_FLAGS_RELEASE "$ENV{CFLAGS} -O3 -Wall")
set(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb")
set(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall")

# --------------------------------------------------------------
add_subdirectory("src")

if(BUILD_WITH_TEST)
    add_subdirectory("test")
endif(BUILD_WITH_TEST)
